package com.yypx.action;

import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.yypx.common.Constants;

public class BaseAction extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware {
	private Map session;
	private HttpServletRequest request;
	private HttpServletResponse response;
	protected Log logger = null;

	public BaseAction() {
		logger = LogFactory.getLog(getClass().getName());
	}

	public Map getSession() {
		return session;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	/**
	 * 从session中获取用户id
	 * 
	 * @return
	 */
	public UUID getUserID() {
		// 返回登录者的ID
		if (session != null && session.get(Constants.SESSION_KEY_USERID) != null) {
			return (UUID) session.get(Constants.SESSION_KEY_USERID);
		} else {
			return UUID.fromString("a59ea9cb-1e75-4266-8a50-6a60a485b54f");
			// return null;
		}
	}
}
